package com.example.demoopcjava.opcua.demo2;

import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;

/**
 * <b><code>OpcUAController</code></b>
 * <p>
 * Description
 * <p>
 * <b>Create Time:</b> 2022/1/10 11:04.
 *
 * @author qd.yt
 * @version 0.0.1
 * @since demo-opc-java v0.0.1
 */
@RestController
@AllArgsConstructor
public class OpcUAController {

    @Autowired
    private OpcUaOperationSupport opcUaOperationSupport;

    @RequestMapping(value = "/", method = RequestMethod.GET)
    public String test() {

        return "hello  ";
    }
    @RequestMapping(value = "/query")
    public ResultBean readPLC(OpcModel server, HttpServletResponse response) throws Exception {
        response = null;
        ResultBean resultBean = opcUaOperationSupport.readPLC(server);
        return resultBean;
    }

    @RequestMapping(value = "/subscription")
    public ResultBean readSubscriptionPLC(OpcModel server, HttpServletResponse response) throws Exception {
        response = null;
        ResultBean resultBean = opcUaOperationSupport.createSubscription(server);
        return resultBean;
    }

    @RequestMapping(value = "/edit")
    public ResultBean writePLC(OpcModel server, String editValue, HttpServletResponse response) throws Exception {
        response = null;
        ResultBean resultBean = opcUaOperationSupport.writePLC(server, editValue);
        return resultBean;
    }
}